﻿using System;
using System.Web.Mvc;

namespace Clover.BaseAuth
{
    public class PermissionCacheSerializer
    {
        public static void SavePermissions(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            Enum[] Permissions = GetPermissions();

            //已经存在缓存数据
            if (Permissions != null && Permissions.Length > 0) return;

            Permissions= PermissionProviders.Providers.GetCurrentPermissions(controllerContext, actionDescriptor);
            DefaultCurrentPermission.Default.SavePermissions(DefaultCurrentIdentity.Default.GetIdentity(), Permissions);
        }

        public static Enum[] GetPermissions()
        {
            return DefaultCurrentPermission.Default.ReadPermissions(DefaultCurrentIdentity.Default.GetIdentity());
        }

    }
}
